package test_modele;

import static org.junit.Assert.*;

import java.io.IOException;
import java.util.ArrayList;
import java.util.Collection;
import java.util.Collections;
import java.util.Iterator;
import java.util.List;

import modele.*;

import org.junit.Before;
import org.junit.Test;
/**
 * 
 * @author Plancq Charlotte, Lanvin Kévin, Darras Raphael
 *
 *
 */
public class TCollection {
	CollectionAlbums collection;
	Album a;
	Album b;
	Bdtheque bdt;
	List<Album> listeTest;
	Collection<Album> collec;
	
	@Before
	public void setUp() throws IOException{
		collection=new CollectionAlbums(bdt,"listeATester");
		a = new Album("Tintin au Tibet", "Hergé", "editeur", "aventure", "Tintin", "synopsis", 5, " "," ");
		b= new Album("Nitnit au Tebit","Géher",null,"l'Aaaaaventura","Nitnit","resumé", 6, "abcd"," ");
		listeTest=new ArrayList<Album>();
		listeTest.add(a);
		listeTest.add(b);
		collec=new Collection<Album>() {

			@Override
			public boolean add(Album e) {
				// TODO Auto-generated method stub
				return false;
			}

			@Override
			public boolean addAll(Collection<? extends Album> c) {
				// TODO Auto-generated method stub
				return false;
			}

			@Override
			public void clear() {
				// TODO Auto-generated method stub
				
			}

			@Override
			public boolean contains(Object o) {
				// TODO Auto-generated method stub
				return false;
			}

			@Override
			public boolean containsAll(Collection<?> c) {
				// TODO Auto-generated method stub
				return false;
			}

			@Override
			public boolean isEmpty() {
				// TODO Auto-generated method stub
				return false;
			}

			@Override
			public Iterator<Album> iterator() {
				// TODO Auto-generated method stub
				return null;
			}

			@Override
			public boolean remove(Object o) {
				// TODO Auto-generated method stub
				return false;
			}

			@Override
			public boolean removeAll(Collection<?> c) {
				// TODO Auto-generated method stub
				return false;
			}

			@Override
			public boolean retainAll(Collection<?> c) {
				// TODO Auto-generated method stub
				return false;
			}

			@Override
			public int size() {
				// TODO Auto-generated method stub
				return 0;
			}

			@Override
			public Object[] toArray() {
				// TODO Auto-generated method stub
				return null;
			}

			@Override
			public <T> T[] toArray(T[] a) {
				// TODO Auto-generated method stub
				return null;
			}
		};
		bdt=new Bdtheque();
		collec.add(a);
		collec.add(b);
		bdt.addAlbum(a, 0);
		bdt.addAlbum(b, 0);
	}
	
	@Test
	public void testContainsAndAdd(){
		collection.add(a);
		assertTrue(collection.contains(a));
		assertFalse(collection.contains(b));
	}
	
	@Test
	public void testRemove(){
		collection.add(a);
		collection.add(b);
		assertTrue(collection.contains(a));
		assertTrue(collection.contains(b));
		collection.remove(b);
		assertTrue(collection.contains(a));
		assertFalse(collection.contains(b));
	}
	
	@Test
	public void testClear(){
		collection.add(a);
		collection.add(b);
		assertTrue(collection.contains(a));
		assertTrue(collection.contains(b));
		collection.clear();
		assertFalse(collection.contains(a));
		assertFalse(collection.contains(b));
	}
	
	@Test
	public void testGetAlbums(){
		List<Album> liste=new ArrayList<Album>();
		liste.add(a);
		collection.add(a);
		assertEquals(liste,collection.getAlbums());
	}
	
	@Test
	public void testGetAlbum(){
		collection.add(a);
		collection.add(b);
		assertEquals(a,collection.getElementAt(0));
		assertEquals(b,collection.getElementAt(1));
	}
	
	@Test
	public void testGetNom(){
		assertEquals("listeATester",collection.getNom());
	}
	
	@Test   
	public void testRecherche(){
		List<Album> liste=new ArrayList<Album>();
		liste.add(a);
		collection.add(a);
		collection.add(b);
		assertEquals(liste, collection.rechercherAlbum(a));
	}

	public void testIterator(){
		assertEquals(listeTest.iterator(), collection.iterator());
	}

	public void testAddAll(){
		assertTrue(collection.addAll(collec));
	}
	
	/*public void testGetSize(){
		assertEquals(0,collection.getSize());
	}
	fonctionne toujours, quelque soit la valeur testée*/

	/*public void testGetElementAt(){
		assertEquals(a, collection.getElementAt(1));
	}idem */
	
	public void testToString(){
		assertEquals("listeATester",collection.getNom());

	}
	
	public void testGetIndexOf(){
		assertEquals(0,collection.getIndexOf(a));
	}
	
	public void testSetNom(){
		collection.setNom("liste");
		assertEquals("liste",collection.getNom());
	}
}
